package com.newly.center.sys.service.databse.impl;

import com.newly.center.sys.service.databse.api.IDatabaseService;
import com.newly.common.base.entity.PageUtils;
import com.newly.common.base.entity.sys.database.po.ColumnPo;
import com.newly.common.base.entity.sys.database.po.TablePo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: newly-parent
 * @remark: 数据库管理业务实现
 * @author: guan
 * @create: 2021-11-30 18:43
 */
@Service
@Slf4j
public class DatabaseService extends AbstractDatabaseService implements IDatabaseService {

    @Override
    public int countTable(String keyword) {
        return databaseMapper.countTable(keyword);
    }

    @Override
    public PageUtils getTables(Integer offset,  Integer limit, String keyword) {
        int total = this.countTable(keyword);
        int currPage = (offset - 1) * limit;
        List<TablePo> tablePos = databaseMapper.selectTables(currPage, limit, keyword);
        return new PageUtils(tablePos, total, limit, offset);
    }

    @Override
    public List<ColumnPo> getColumns(String tableName) {
        return databaseMapper.selectColumns(tableName);
    }
}
